package com.aha.thirdchapter.first;

/**
 * Mathematical Olympiad坑爹的奥数
 * 1、X3*6528=3X*8256   求满足等式的x的值
 * 2、abc+def=ghi  不重复满足这个等式
 * Created by wangxin on 2015/11/3.
 */
public class OMath {
    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            if((10*i+3)*6528 == (30+i)*8256) System.out.println(i);
        }
        int[] a = new int[9];
        int[] book = new int[10];
        int sum = 0;
        int total=0;
        for (a[0] = 1; a[0] <= 9; a[0]++)
            for (a[1] = 1; a[1] <= 9; a[1]++)
                for (a[2] = 1; a[2] <= 9; a[2]++)
                    for (a[3] = 1; a[3] <= 9; a[3]++)
                        for (a[4] = 1; a[4] <= 9; a[4]++)
                            for (a[5] = 1; a[5] <= 9; a[5]++)
                                for (a[6] = 1; a[6] <= 9; a[6]++)
                                    for (a[7] = 1; a[7] <= 9; a[7]++)
                                        for (a[8] = 1; a[8] <= 9; a[8]++){
                                            //重置book
                                            for (int i = 0; i <= 9; i++) {
                                                book[i] = 0;
                                            }
                                            for (int i = 0; i < 9; i++) {
                                                int c = a[i];
                                                book[c] = 1;
                                            }
                                            sum = 0;
                                            for (int i = 0; i <= 9; i++) {
                                                sum+=book[i];
                                            }
                                            if(sum==9 && (a[0]*100+a[1]*10+a[2]+a[3]*100+a[4]*10+a[5]==a[6]*100+a[7]*10+a[8])){
                                                total++;
                                                System.out.println(a[0]+""+a[1]+""+a[2]+"+"+a[3]+""+a[4]+""+a[5]+"="+a[6]+""+a[7]+""+a[8]);
                                            }
                                        }
        System.out.println("共"+total/2);
    }
}
